<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<!-- 2、版本依赖
> 假设我们要去简化一个大型项目中，某个包的依赖版本
> 给定一个如下的版本信息数据结构，计算出一个符合所有要求的版本区间，如果没有返回 false
const ranges = [{ from: '1.0.0', to: '2.0.0' }, 
                { from: '0.1.0', to: '1.5.0' }, 
                { from: '1.2.0', to: '1.2.0' }]; -->

<body>
    <div>test13-2</div>
    <script>
        const ranges = [{ from: '1.0.0', to: '2.0.0' },
        { from: '0.1.0', to: '1.5.0' },
        { from: '1.2.0', to: '1.2.0' }]
        function aaa(ranges) {
            let fromMax = []
            let toMin = []
            let max
            let min
            for (let i = 0; i < ranges.length; i++) {
                fromMax.push(ranges[i].from.split('.'))
                toMin.push(ranges[i].to.split('.'))
            }
            
            function loop(fn){
                fn.sort((a,b)=>{
                return a[0] - b[0] || a[1] - b[1] || a[2] - b[2]
            })
            for (let i = 0; i < fn.length; i++) {
                fn[i] = fn[i].join()
            }
            return fn
            }
            loop(fromMax)
            loop(toMin)
            console.log(fromMax)
            console.log(toMin)
            max = fromMax[fromMax.length-1]
            min = toMin[0]
           return [max, min] ? [max, min] : false
        }
        console.log(aaa(ranges))
    </script>
</body>

</html>